//
//  Global.m
//  Test
//
//  Created by 曾威林 on 2017/12/27.
//  Copyright © 2017年 jingyao. All rights reserved.
//

#import "Global.h"

@implementation Global

CGFloat cRate = 0.0f;
UIStoryboard *mainStoryboard = nil;

//初始化全局storyboard
+ (void)setUpGlobalStoryboard {
    mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
}

//判断手机型号
+ (NSString *)iphoneType {
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *platform = [NSString stringWithCString: systemInfo.machine encoding:NSASCIIStringEncoding];
    
    if([platform isEqualToString:@"iPhone7,1"]) {return @"6p";}
    else if([platform isEqualToString:@"iPhone7,2"]) {return @"6";}
    else if([platform isEqualToString:@"iPhone8,1"]) {return @"6s";}
    else if([platform isEqualToString:@"iPhone8,2"]) {return @"6p";}
    else if([platform isEqualToString:@"iPhone8,4"]) {return @"se";}
    else if([platform isEqualToString:@"iPhone9,1"]) {return @"7";}
    else if([platform isEqualToString:@"iPhone9,2"]) {return @"7p";}
    else if([platform isEqualToString:@"iPhone10,1"]) {return @"8";}
    else if([platform isEqualToString:@"iPhone10,4"]) {return @"8";}
    else if([platform isEqualToString:@"iPhone10,2"]) {return @"8p";}
    else if([platform isEqualToString:@"iPhone10,5"]) {return @"8p";}
    else if([platform isEqualToString:@"iPhone10,3"]) {return @"x";}
    else if([platform isEqualToString:@"iPhone10,6"]) {return @"x";}
    return platform;
}

//显示提示框
+ (void)showTextOnly:(NSString*)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
        hud.mode = MBProgressHUDModeText;
        hud.label.text = text;
        hud.label.font = [UIFont systemFontOfSize:12];
        hud.margin = 10.f;
        hud.offset = CGPointMake(0, 160.0f);
        hud.removeFromSuperViewOnHide = YES;
        
        [hud hideAnimated:YES afterDelay:4];
    });
}


#pragma mark - token相关操作

+ (void)saveTokenWithToken:(NSString *)token {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:token forKey:@"token"];
    [userDefaults synchronize];
}

+ (NSString *)getToken {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *str = [userDefaults objectForKey:@"token"];
    return str;
}

+ (void)deleteToken {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults removeObjectForKey:@"token"];
}

@end
